/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package database;

/**
 *
 * @author Asus
 */


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class KoneksiMySQL {

    public static void main(String[] args) {
        try {

            Class.forName("com.mysql.jdbc.Driver").newInstance();

            Connection koneksi = DriverManager.getConnection("jdbc:mysql://localhost:3306/pti", "root", "");

            System.out.println("Koneksi ke database PTI di MySQL berhasil");
            
            
            Statement stmt = koneksi.createStatement();
            ResultSet rs= stmt.executeQuery("select * from divisi");
            while(rs.next()){
            String name= rs.getString("namaDivisi");               
            System.out.println(name);
            System.out.println("Done..");
            }

        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException ex) {
            System.err.println("Terjadi kesalahan : " + ex.getMessage());
        }
    }
}

